/*
 * http://www.java-forums.org/java-applets/2567-how-import-picture-into-applet.html
 */

/*
 * main.java
 *
 * Created on Dec 11, 2011, 7:31:51 PM
 */
package jmediaplayer;

import com.almworks.sqlite4java.SQLiteConnection;
import jtmdb.Genre;
import jtmdb.Movie;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeNode;
import jmediaplayer.threads.ThreadLoadMedia;
import jmediaplayer.threads.ThreadLoadMediaImage;

/**
 *
 * @author Deano
 */
public class FormMain extends javax.swing.JFrame {
	//SETUP
	//Perhaps we should move some stuff into classes? hmm settings class :)
	private ImageIcon FolderIconOpen = new ImageIcon(getClass().getResource("/icons/folder_open.png"));
	private ImageIcon FolderIconClosed = new ImageIcon(getClass().getResource("/icons/folder_closed.png"));
	private SQLiteConnection dbMS;
	private SQLiteConnection dbS;
	private String[] SupportedFormats = {"mp3","avi"};

	public static boolean mSkipAll = false;
	public static boolean mAddAll = false;
	public static boolean mSkip = false;

	private Boolean LMThreadRun = false;

	private static int MSListIndex = 0;

	//NMForm
	private static ArrayList<String[]> movieFeedArray = new ArrayList<String[]>();
	public static String NMOrigName = "";
	public static String NMOrigPath = "";
	public static String NMOrigExt = "";
	public static String NMHash = "";

	/** Creates new form main */
	public FormMain() {
		//startup settings class
		new setting();

		dbMS = new SQLiteConnection(new File(setting.get("storeDirectory") + "MediaStore.db"));
		dbS = new SQLiteConnection(new File(setting.get("storeDirectory") + "Settings.db"));

		//set window fullscreen
		if (setting.getI("fullscreen") == 1) {
				setUndecorated(true);
				setExtendedState(FormMain.MAXIMIZED_BOTH);
		}
		pack();
		initComponents();

	}

	/** This method is called from within the constructor to
	 * initialise the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        NMDialog = new javax.swing.JDialog();
        NMAdd = new javax.swing.JButton();
        NMTitle = new javax.swing.JLabel();
        NMSeparator = new javax.swing.JSeparator();
        NMLabel1 = new javax.swing.JLabel();
        NMSkipAll = new javax.swing.JButton();
        NMTabbedPane = new javax.swing.JTabbedPane();
        NMPaneMainInfo = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        NMName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        NMDesc = new javax.swing.JTextPane();
        NMLPath = new javax.swing.JLabel();
        NMFetchTMDb = new javax.swing.JButton();
        NMPaneExtraInfo = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        NMGenres = new javax.swing.JTextPane();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        NMTags = new javax.swing.JTextPane();
        jScrollPane6 = new javax.swing.JScrollPane();
        NMCats = new javax.swing.JTextPane();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        NMPaneEpisodeInfo = new javax.swing.JPanel();
        NMEpisodeName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        NMEpisodes = new javax.swing.JTextField();
        NMEpisodeNo = new javax.swing.JTextField();
        NMPaneImages = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        NMSkip = new javax.swing.JButton();
        NMAddAll = new javax.swing.JButton();
        MSDialog = new javax.swing.JDialog();
        MSLabel1 = new javax.swing.JLabel();
        MSSeparator = new javax.swing.JSeparator();
        MSLabel2 = new javax.swing.JLabel();
        MSCancel = new javax.swing.JButton();
        MSOk = new javax.swing.JButton();
        MSLoading = new javax.swing.JLabel();
        MSName = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        MSSearch = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane7 = new javax.swing.JScrollPane();
        MSList = new javax.swing.JList();
        jScrollPane8 = new javax.swing.JScrollPane();
        MSDescription = new javax.swing.JTextArea();
        jButton2 = new javax.swing.JButton();
        LabelSoftwareTitle = new javax.swing.JLabel();
        CloseForm = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        MediaTree = new javax.swing.JTree();
        debug = new javax.swing.JTextField();
        FormSettings = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jMediaLister = new mediaLister.MediaLister();
        jSeparator1 = new javax.swing.JSeparator();

        NMDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        NMDialog.setAlwaysOnTop(true);
        NMDialog.setFocusCycleRoot(false);
        NMDialog.setMinimumSize(new java.awt.Dimension(436, 392));
        NMDialog.setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        NMDialog.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        NMDialog.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                NMDialogComponentShown(evt);
            }
        });

        NMAdd.setText("Add");
        NMAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NMAddActionPerformed(evt);
            }
        });

        NMTitle.setFont(new java.awt.Font("Cooper Black", 0, 24));
        NMTitle.setText("Add New Media");

        NMLabel1.setText("<html>\nNew media has been detected, please review the information below and click \"add\" to add the media into jMediaPlayer.\n</html>");
        NMLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        NMLabel1.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        NMSkipAll.setText("Skip All");
        NMSkipAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NMSkipAllActionPerformed(evt);
            }
        });

        jLabel2.setText("Name:");

        jLabel3.setText("Description:");

        jScrollPane3.setViewportView(NMDesc);

        NMLPath.setText("<html> <b>Path:</b> <font style=\"color:red\">path/path</font> </html>");

        NMFetchTMDb.setText("Fetch info using TMDb");
        NMFetchTMDb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NMFetchTMDbActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout NMPaneMainInfoLayout = new javax.swing.GroupLayout(NMPaneMainInfo);
        NMPaneMainInfo.setLayout(NMPaneMainInfoLayout);
        NMPaneMainInfoLayout.setHorizontalGroup(
            NMPaneMainInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMPaneMainInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(NMPaneMainInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NMLPath, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                    .addGroup(NMPaneMainInfoLayout.createSequentialGroup()
                        .addGroup(NMPaneMainInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(NMPaneMainInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(NMPaneMainInfoLayout.createSequentialGroup()
                                .addComponent(NMName, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                                .addGap(181, 181, 181))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                            .addComponent(NMFetchTMDb))))
                .addContainerGap())
        );
        NMPaneMainInfoLayout.setVerticalGroup(
            NMPaneMainInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMPaneMainInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(NMLPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(NMPaneMainInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(NMName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(NMPaneMainInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(NMFetchTMDb)
                .addContainerGap())
        );

        NMTabbedPane.addTab("Main Info", NMPaneMainInfo);

        jLabel6.setText("Genres:");

        jScrollPane4.setViewportView(NMGenres);

        jLabel7.setText("Tags:");

        jScrollPane5.setViewportView(NMTags);

        jScrollPane6.setViewportView(NMCats);

        jLabel8.setText("Categories:");

        jLabel9.setText("<html>You can input several by placing a comma followed by a space between each.<br>For example: <b>first, second, third</b></html>");

        javax.swing.GroupLayout NMPaneExtraInfoLayout = new javax.swing.GroupLayout(NMPaneExtraInfo);
        NMPaneExtraInfo.setLayout(NMPaneExtraInfoLayout);
        NMPaneExtraInfoLayout.setHorizontalGroup(
            NMPaneExtraInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMPaneExtraInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(NMPaneExtraInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(NMPaneExtraInfoLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(36, 36, 36)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE))
                    .addGroup(NMPaneExtraInfoLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(47, 47, 47)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE))
                    .addGroup(NMPaneExtraInfoLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE))
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        NMPaneExtraInfoLayout.setVerticalGroup(
            NMPaneExtraInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, NMPaneExtraInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(NMPaneExtraInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(NMPaneExtraInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(NMPaneExtraInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        NMTabbedPane.addTab("Extra Info", NMPaneExtraInfo);

        jLabel4.setText("Name:");

        jLabel1.setText("Episode:");

        jLabel5.setText("of");

        NMEpisodes.setEditable(false);
        NMEpisodes.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        NMEpisodes.setText("99");

        NMEpisodeNo.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        NMEpisodeNo.setText("1");

        javax.swing.GroupLayout NMPaneEpisodeInfoLayout = new javax.swing.GroupLayout(NMPaneEpisodeInfo);
        NMPaneEpisodeInfo.setLayout(NMPaneEpisodeInfoLayout);
        NMPaneEpisodeInfoLayout.setHorizontalGroup(
            NMPaneEpisodeInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMPaneEpisodeInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(NMPaneEpisodeInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(NMPaneEpisodeInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NMEpisodeName, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(NMPaneEpisodeInfoLayout.createSequentialGroup()
                        .addComponent(NMEpisodeNo, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NMEpisodes, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(154, Short.MAX_VALUE))
        );
        NMPaneEpisodeInfoLayout.setVerticalGroup(
            NMPaneEpisodeInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMPaneEpisodeInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(NMPaneEpisodeInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(NMEpisodeName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(NMPaneEpisodeInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(NMEpisodeNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(NMEpisodes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(133, Short.MAX_VALUE))
        );

        NMTabbedPane.addTab("Episode Info", NMPaneEpisodeInfo);

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/shot80.png"))); // NOI18N

        jLabel12.setText("Preview:");

        jTextField1.setText("jTextField1");

        jLabel13.setText("URL:");

        jLabel14.setText("Or:");

        jButton1.setText("Browse...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Get from TMDB");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout NMPaneImagesLayout = new javax.swing.GroupLayout(NMPaneImages);
        NMPaneImages.setLayout(NMPaneImagesLayout);
        NMPaneImagesLayout.setHorizontalGroup(
            NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMPaneImagesLayout.createSequentialGroup()
                .addGroup(NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(NMPaneImagesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addGap(18, 18, 18)
                        .addGroup(NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(NMPaneImagesLayout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3))
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)))
                    .addGroup(NMPaneImagesLayout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel12)))
                .addContainerGap())
        );
        NMPaneImagesLayout.setVerticalGroup(
            NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMPaneImagesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(NMPaneImagesLayout.createSequentialGroup()
                        .addGroup(NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(NMPaneImagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(jButton1)
                            .addComponent(jButton3)))
                    .addComponent(jLabel11))
                .addContainerGap(84, Short.MAX_VALUE))
        );

        NMTabbedPane.addTab("Image", NMPaneImages);

        NMSkip.setText("Skip");
        NMSkip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NMSkipActionPerformed(evt);
            }
        });

        NMAddAll.setText("Add All");
        NMAddAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NMAddAllActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout NMDialogLayout = new javax.swing.GroupLayout(NMDialog.getContentPane());
        NMDialog.getContentPane().setLayout(NMDialogLayout);
        NMDialogLayout.setHorizontalGroup(
            NMDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(NMDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(NMTabbedPane)
                    .addComponent(NMLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(NMSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                    .addComponent(NMTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                    .addGroup(NMDialogLayout.createSequentialGroup()
                        .addComponent(NMAdd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NMSkip)
                        .addGap(18, 18, 18)
                        .addComponent(NMAddAll)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NMSkipAll)))
                .addContainerGap())
        );
        NMDialogLayout.setVerticalGroup(
            NMDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NMDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(NMTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(NMSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(NMLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(NMTabbedPane)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(NMDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NMSkipAll)
                    .addComponent(NMAddAll)
                    .addComponent(NMSkip)
                    .addComponent(NMAdd))
                .addContainerGap())
        );

        NMDialog.getAccessibleContext().setAccessibleParent(this);

        MSDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        MSDialog.setAlwaysOnTop(true);
        MSDialog.setFocusCycleRoot(false);
        MSDialog.setMinimumSize(new java.awt.Dimension(436, 392));
        MSDialog.setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        MSDialog.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        MSDialog.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                MSDialogWindowActivated(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                MSDialogWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                MSDialogWindowOpened(evt);
            }
        });

        MSLabel1.setFont(new java.awt.Font("Cooper Black", 0, 24));
        MSLabel1.setText("Media Suggestions");

        MSLabel2.setText("<html>\njMediaPlayer uses the TMDb API to fetch Movie information for your media, please review the list of movie suggestions below (if any) and select your media. Alternatively you may change the search query or cancel the operation if you cannot find a suitable match.\n</html>");
        MSLabel2.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        MSLabel2.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        MSCancel.setText("Cancel");
        MSCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MSCancelActionPerformed(evt);
            }
        });

        MSOk.setText("Ok");
        MSOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MSOkActionPerformed(evt);
            }
        });

        MSLoading.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/loader20.gif"))); // NOI18N
        MSLoading.setText("Loading...");

        MSName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                MSNameFocusGained(evt);
            }
        });

        jLabel10.setText("Search Term:");

        MSSearch.setText("Search");
        MSSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MSSearchActionPerformed(evt);
            }
        });

        jSplitPane1.setDividerLocation(200);

        MSList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                MSListMouseClicked(evt);
            }
        });
        jScrollPane7.setViewportView(MSList);

        jSplitPane1.setLeftComponent(jScrollPane7);

        MSDescription.setColumns(20);
        MSDescription.setEditable(false);
        MSDescription.setLineWrap(true);
        MSDescription.setRows(5);
        MSDescription.setWrapStyleWord(true);
        jScrollPane8.setViewportView(MSDescription);

        jSplitPane1.setRightComponent(jScrollPane8);

        javax.swing.GroupLayout MSDialogLayout = new javax.swing.GroupLayout(MSDialog.getContentPane());
        MSDialog.getContentPane().setLayout(MSDialogLayout);
        MSDialogLayout.setHorizontalGroup(
            MSDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MSDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(MSDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
                    .addComponent(MSLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
                    .addComponent(MSSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
                    .addGroup(MSDialogLayout.createSequentialGroup()
                        .addComponent(MSLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
                        .addGap(26, 26, 26))
                    .addGroup(MSDialogLayout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MSName, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MSSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(MSDialogLayout.createSequentialGroup()
                        .addComponent(MSLoading)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MSOk)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MSCancel)))
                .addContainerGap())
        );
        MSDialogLayout.setVerticalGroup(
            MSDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MSDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(MSLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MSSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MSLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addGroup(MSDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MSName)
                    .addComponent(MSSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
                .addGroup(MSDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(MSLoading, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(MSCancel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(MSOk, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );

        MSDialog.getAccessibleContext().setAccessibleParent(this);

        jButton2.setText("Browse...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        LabelSoftwareTitle.setFont(new java.awt.Font("Cooper Black", 0, 24));
        LabelSoftwareTitle.setText("jMediaPlayer 0.1");

        CloseForm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/close.png"))); // NOI18N
        CloseForm.setBorder(null);
        CloseForm.setBorderPainted(false);
        CloseForm.setContentAreaFilled(false);
        CloseForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CloseFormActionPerformed(evt);
            }
        });

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Media");
        MediaTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        MediaTree.setToggleClickCount(1);
        MediaTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                MediaTreeValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(MediaTree);

        debug.setText("debug");

        FormSettings.setText("Settings");
        FormSettings.setToolTipText("Change Settings");
        FormSettings.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FormSettingsActionPerformed(evt);
            }
        });

        jScrollPane2.setViewportView(jMediaLister);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 853, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(LabelSoftwareTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 618, Short.MAX_VALUE)
                        .addGap(200, 200, 200)
                        .addComponent(CloseForm))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(FormSettings, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(debug, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LabelSoftwareTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CloseForm))
                .addGap(2, 2, 2)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(debug, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(FormSettings)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void CloseFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseFormActionPerformed
	dispose();
}//GEN-LAST:event_CloseFormActionPerformed

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened


	NMDialog.setLocationRelativeTo(getRootPane());
	MSDialog.setLocationRelativeTo(getRootPane());
	//Make sure full screen is active
	if (setting.getI("fullscreen") == 1) {
		setExtendedState(FormMain.MAXIMIZED_BOTH);
	}

	//JFileChooser fc = new JFileChooser();
	//int returnVal = fc.showOpenDialog(main.this);
	//File file = fc.getSelectedFile();

	//try {
	//	jTextField1.setText(OpenSubtitlesHasher.computeHash(file));
	//} catch (IOException ex) {
	//	Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
	//}

	FileTree.getFolders(setting.get("mediaDirectory"),MediaTree);

	if (FolderIconClosed != null && FolderIconOpen != null) {
		//jTree1.setCellRenderer(new MyRenderer(FolderIcon));
		DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
		renderer.setLeafIcon(FolderIconClosed);
		renderer.setOpenIcon(FolderIconOpen);
		renderer.setClosedIcon(FolderIconClosed);
		MediaTree.setCellRenderer(renderer);
	}
	//MovieImages images = new MovieImages(1, "1c184f4");
}//GEN-LAST:event_formWindowOpened

private void FormSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FormSettingsActionPerformed
		FormSettings FSettings = new FormSettings();
		if (setting.getI("fullscreen") == 1) {
			FSettings.dispose();
			FSettings.setUndecorated(true);
			FSettings.setExtendedState(FormMain.MAXIMIZED_BOTH);
		}
		FSettings.setVisible(true);
}//GEN-LAST:event_FormSettingsActionPerformed

    private void MediaTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_MediaTreeValueChanged
		DefaultMutableTreeNode node = (DefaultMutableTreeNode) MediaTree.getLastSelectedPathComponent();


		if (node == null) {
			//nothing to do
		} else {
			String nodePath = "";
			List nodeArray = new ArrayList();

			//if (node.isLeaf()) {
				TreeNode[] tp = node.getPath();
				for (TreeNode tn : tp) {
					nodePath += tn + "/";
					nodeArray.add(tn);
				}
			//} else {
			//	Object nodeInfo = node.getUserObject();
			//	nodePath = nodeInfo.toString();
			//	nodeArray.add(nodePath);
			//}

			//debug
			System.out.println("Node Selected: " + nodePath);
			//JOptionPane.showMessageDialog(this, "Eggs are not supposed to be green.");

			//We have the path
			//now we need to fetch all the files, and create the list.
			//MediaFunctions.DropMediaToPanel(nodePath, nodeArray);
			if (LMThreadRun == true) {
				LMThreadRun = false;

				//tell the thread to abort!
				ThreadLoadMedia.abortThread = true;

				//Lets do some waiting
				UsefulFunctions.waiting(200);
			}

			Runnable r = new ThreadLoadMedia(nodePath, nodeArray);
			Thread LMThread = new Thread(r);
			LMThread.start();
			LMThreadRun = true;

			//String[] d = UsefulFunctions.mediaData.get(0);
			//System.out.println("Test: " + d[0]);
		}
    }//GEN-LAST:event_MediaTreeValueChanged

	private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
		// TODO add your handling code here for when the window closes
		dbMS.dispose();
		dbS.dispose();
		NMDialog.dispose();
		MSDialog.dispose();
	}//GEN-LAST:event_formWindowClosing

private void NMAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NMAddActionPerformed
	//We should do any file alterations now (add all obviously doesnt change filenames ;)
	File fileold = new File(NMOrigPath + NMOrigName + NMOrigExt);
	//TODO: Make NMName safe.
	File filenew = new File(NMOrigPath + NMName.getText() + NMOrigExt);

	// Rename file (or directory)
	boolean success = fileold.renameTo(filenew);

	if (success) {
		NMOrigName = NMName.getText();
	} else {
		// File was not successfully renamed
		System.out.println("Could not rename the file.");
	}

	//Close the form, we read the form after disposal :)
	NMDialog.dispose();
}//GEN-LAST:event_NMAddActionPerformed

private void NMSkipAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NMSkipAllActionPerformed
	//Skip all found media files.
	mSkipAll = true;
	NMDialog.dispose();
}//GEN-LAST:event_NMSkipAllActionPerformed

	private void NMDialogComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_NMDialogComponentShown
		NMDialog.setLocationRelativeTo(getRootPane());
	}//GEN-LAST:event_NMDialogComponentShown

	private void NMSkipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NMSkipActionPerformed
		//Skip this media file.
		mSkip = true;
		NMDialog.dispose();
	}//GEN-LAST:event_NMSkipActionPerformed

	private void NMAddAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NMAddAllActionPerformed
		//add all media
		mAddAll = true;
		NMDialog.dispose();
	}//GEN-LAST:event_NMAddAllActionPerformed

private void MSCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MSCancelActionPerformed
	MSDialog.setVisible(false);
	NMDialog.setVisible(true);
}//GEN-LAST:event_MSCancelActionPerformed

private void MSOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MSOkActionPerformed

	MSLoading.setVisible(true);

	//disable the containers
	MSCancel.setEnabled(false);
	MSDescription.setEnabled(false);
	MSList.setEnabled(false);
	MSOk.setEnabled(false);
	MSSearch.setEnabled(false);
	MSName.setEnabled(false);

	Runnable r = new ThreadLoadMediaImage(movieFeedArray.get(5)[MSListIndex],NMHash);
	Thread LMIThread = new Thread(r);
	LMIThread.start();

}//GEN-LAST:event_MSOkActionPerformed

//This is called to complete the MSOk from the thread :)
public static void MSOKActionPerformedComplete() {
	//Set NMDialog data!
	NMName.setText(movieFeedArray.get(0)[MSListIndex]);
	NMDesc.setText(movieFeedArray.get(1)[MSListIndex]);
	NMGenres.setText(movieFeedArray.get(2)[MSListIndex] + movieFeedArray.get(4)[MSListIndex]);
	NMTags.setText(movieFeedArray.get(3)[MSListIndex]);

	//enable the containers
	MSCancel.setEnabled(true);
	MSDescription.setEnabled(true);
	MSList.setEnabled(true);
	MSOk.setEnabled(false);
	MSSearch.setEnabled(true);
	MSName.setEnabled(true);
	MSLoading.setVisible(false);

	MSDialog.setVisible(false);
	NMDialog.setVisible(true);
}

private void NMFetchTMDbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NMFetchTMDbActionPerformed
	//Send data to the form
	MSName.setText(NMName.getText());

	NMDialog.setVisible(false);
	MSDialog.setVisible(true);
}//GEN-LAST:event_NMFetchTMDbActionPerformed

private void MSDialogWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_MSDialogWindowClosing
	//Clean up
	movieFeedArray.clear();

	//AutoMedia for some reason is not disposed in time for addNewMedia's capture of the screen, so quick fix hide it ;)
	MSDialog.setVisible(false);
	NMDialog.setVisible(true);
}//GEN-LAST:event_MSDialogWindowClosing

private void MSSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MSSearchActionPerformed
	//Clean up
	movieFeedArray.clear();

	//Load JTDBb (copy of AutoMediaWindowActivated)
	Thread thr1 = new Thread(ThreadSearch);
	thr1.start();
}//GEN-LAST:event_MSSearchActionPerformed

private void MSListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MSListMouseClicked
	MSListIndex = MSList.locationToIndex(evt.getPoint());
    System.out.println("Selected item ID: " + MSListIndex);
	MSDescription.setText(movieFeedArray.get(1)[MSListIndex]);
	MSDescription.setSelectionStart(0);
	MSDescription.setSelectionEnd(0);

	MSOk.setEnabled(true);
}//GEN-LAST:event_MSListMouseClicked

private void MSNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_MSNameFocusGained
	//Experiment - wipe data
	//MSName.setText("");
}//GEN-LAST:event_MSNameFocusGained

private void MSDialogWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_MSDialogWindowOpened

}//GEN-LAST:event_MSDialogWindowOpened

	private void MSDialogWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_MSDialogWindowActivated
		Thread thr1 = new Thread(ThreadSearch);
		thr1.start();
	}//GEN-LAST:event_MSDialogWindowActivated

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		// TODO add your handling code here:
	}//GEN-LAST:event_jButton1ActionPerformed

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
		// TODO add your handling code here:
	}//GEN-LAST:event_jButton2ActionPerformed

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
		// TODO add your handling code here:
	}//GEN-LAST:event_jButton3ActionPerformed

//thread
Runnable ThreadSearch = new Runnable() {
	@Override
	public void run() {
		//disable and show loading
		MSLoading.setVisible(true);
		MSList.setEnabled(false);
		MSSearch.setEnabled(false);
		MSName.setEnabled(false);
		MSDescription.setEnabled(false);
		MSOk.setEnabled(false);


		//do search
		List<Movie> movies = UsefulFunctions.searchJTMDB(MSName.getText());

		movieFeedArray.clear();

		//ref564324 - need to add array to each arraymap
		movieFeedArray.add(new String[movies.size()]);
		movieFeedArray.add(new String[movies.size()]);
		movieFeedArray.add(new String[movies.size()]);
		movieFeedArray.add(new String[movies.size()]);
		movieFeedArray.add(new String[movies.size()]);
		movieFeedArray.add(new String[movies.size()]);

		if (movies.size() > 0) {
			int i = 0;
			for (Movie movie : movies) {
				//Sometimes null is being returned... why? who knows.
				if (movie.getName() != null) {
					System.out.println("====================");
					System.out.println("Name: " + movie.getName());
					System.out.println("Type: " + movie.getMovieType());
					System.out.println("Tagline: " + movie.getTagline());
					System.out.println("AltName: " + movie.getAlternativeName());
					System.out.println("OrigName: " + movie.getOriginalName());
					System.out.println("Rating: " + movie.getRating());

					//add each value into the array - dont forget to set ref564324
					movieFeedArray.get(0)[i] = movie.getName();
					movieFeedArray.get(1)[i] = movie.getOverview();
					movieFeedArray.get(2)[i] = movie.getMovieType();
					movieFeedArray.get(3)[i] = movie.getTagline();


					//BUG: #1 - Seems to be a problem with JTMDb
					Set<Genre> genresx = movie.getGenres();
					Object[] genres = genresx.toArray();
					String g = "";

					for(int j=0;j<genres.length;j++) {
						if (j > 0) {
							g +=", ";
						}
						g += genres[j];
					}

					movieFeedArray.get(4)[i] = g;
					movieFeedArray.get(5)[i] = String.valueOf(movie.getID());

					System.out.println(g);

					i++;
				}
			}
			MSList.setEnabled(true);
			MSDescription.setText("Click a result to see more infromation here. Click 'Ok' to load the meta information for the selected result.");
		} else {
			MSDescription.setText("No results for your query.");
		}

		//dispose
		movies.clear();

		MSList.setListData(movieFeedArray.get(0));

		//enable and hide loading
		MSLoading.setVisible(false);
		MSSearch.setEnabled(true);
		MSName.setEnabled(true);
		MSDescription.setEnabled(true);
	}
};

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Default look and feel */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
		 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			//for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				//if ("Metal".equals(info.getName())) {
				//	javax.swing.UIManager.setLookAndFeel(info.getClassName());
				//	break;
				//}
			//}
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		//</editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				FormMain FMain = new FormMain();
				FMain.setVisible(true);
			}
		});
	}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CloseForm;
    public static javax.swing.JButton FormSettings;
    private javax.swing.JLabel LabelSoftwareTitle;
    private static javax.swing.JButton MSCancel;
    private static javax.swing.JTextArea MSDescription;
    public static javax.swing.JDialog MSDialog;
    private javax.swing.JLabel MSLabel1;
    private javax.swing.JLabel MSLabel2;
    private static javax.swing.JList MSList;
    public static javax.swing.JLabel MSLoading;
    private static javax.swing.JTextField MSName;
    private static javax.swing.JButton MSOk;
    private static javax.swing.JButton MSSearch;
    private javax.swing.JSeparator MSSeparator;
    private javax.swing.JTree MediaTree;
    private javax.swing.JButton NMAdd;
    private javax.swing.JButton NMAddAll;
    public static javax.swing.JTextPane NMCats;
    public static javax.swing.JTextPane NMDesc;
    public static javax.swing.JDialog NMDialog;
    public static javax.swing.JTextField NMEpisodeName;
    public static javax.swing.JTextField NMEpisodeNo;
    public static javax.swing.JTextField NMEpisodes;
    private javax.swing.JButton NMFetchTMDb;
    public static javax.swing.JTextPane NMGenres;
    public static javax.swing.JLabel NMLPath;
    private javax.swing.JLabel NMLabel1;
    public static javax.swing.JTextField NMName;
    private javax.swing.JPanel NMPaneEpisodeInfo;
    private javax.swing.JPanel NMPaneExtraInfo;
    private javax.swing.JPanel NMPaneImages;
    private javax.swing.JPanel NMPaneMainInfo;
    private javax.swing.JSeparator NMSeparator;
    public static javax.swing.JButton NMSkip;
    private javax.swing.JButton NMSkipAll;
    private javax.swing.JTabbedPane NMTabbedPane;
    public static javax.swing.JTextPane NMTags;
    private javax.swing.JLabel NMTitle;
    private javax.swing.JTextField debug;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    public static mediaLister.MediaLister jMediaLister;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
